import Vue from 'vue';
import confirm from './cm_confirm2.vue';
import toast from './cm_toast';

let confirmConstructor = Vue.extend(confirm);
let toastConstructor = Vue.extend(toast);
let theConfirm = function  (text) {
  return new Promise((res, rej) => { //promise封装，ok执行resolve，no执行reject
    let confirmDom = new confirmConstructor().$mount()//手动渲染模态框
    // ({
    //   el: document.createElement('div')
    // })
    document.body.appendChild(confirmDom.$el);  //new一个对象，然后插入body里面

    confirmDom.text = text;   //为了使confirm的扩展性更强，这个采用对象的方式传入，所有的字段都可以根据需求自定义
    // console.log(confirmDom)
    confirmDom.ok = function () {
      res()
      confirmDom.isShow = false
    }
    confirmDom.close = function () {
      rej()
      confirmDom.isShow = false
    }

  })
}
let theToast = function (text) {
  let toastDom = new toastConstructor().$mount()//手动渲染模态框
  document.body.appendChild(toastDom.$el);  //new一个对象，然后插入body里面
  toastDom.text = text;
  // console.log(toastDom)
  setTimeout(() => {
    toastDom.toastShow = false
  }, 1500)
}

export  {theConfirm,theToast}

